package me.shurufa.receiver;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.baidu.android.pushservice.PushMessageReceiver;
import com.google.gson.Gson;

import java.util.List;

import me.shurufa.activities.MainActivity;
import me.shurufa.utils.Global;

/**
 * Created by kHRYSTAL on 15/11/19.
 */
public class PushReceiver extends PushMessageReceiver {

    private static final String LOG_TAG = "NumaPush";
    Gson mGson = new Gson();
    NotificationManager notificationManager;
    @Override
    public void onBind(final Context context, final int errorCode, String appid,
                       String userId, String channelId, String requestId) {
        if (errorCode == 0) {
            Global.BAIDU_USER_ID = userId;
            Global.BAIDU_CHANNEL_ID = channelId;
            Log.d(LOG_TAG,""+userId + "  " +channelId);
            //TODO 这里需要向App服务器发送请求绑定AppUID与baiduChannelID

        }
    }

    @Override
    public void onMessage(final Context context, String message, String customContentString) {
        Log.e(LOG_TAG, "**********Get push:" + message);
//        MessageUtils.asyncUpdateMsg(context);
        if (message == null) {
            return;
        }
    }

    @Override
    public void onNotificationClicked(Context context, String title, String description, String customContentString) {
        Intent intent = new Intent();
        intent.setClass(context.getApplicationContext(), MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.getApplicationContext().startActivity(intent);
    }

    @Override
    public void onNotificationArrived(Context context, String s, String s1, String s2) {

    }


    @Override
    public void onSetTags(Context context, int errorCode, List<String>
            successTags, List<String> failTags, String requestId) {
    }

    @Override
    public void onDelTags(Context context, int errorCode, List<String> successTags, List<String> failTags, String requestId) {
    }

    @Override
    public void onListTags(Context context, int errorCode, List<String> tags, String requestId) {
    }

    @Override
    public void onUnbind(Context context, int errorCode, String requestId) {
    }

}
